{include file="public/head" /}
</head>
<body class="layui-layout-body">
<div class="layui-row">
    <div class="layui-col-xs12">
        <ul class="layui-nav" lay-filter="">
            <li class="layui-nav-item">欢迎您,李华</li>
            <li class="layui-nav-item" style="float: right">
                <a href="javascript:;">操作</a>
                <dl class="layui-nav-child">
                    <dd><a href="/user/Index/index">借阅中</a></dd>
                    <dd><a href="/user/Index/history">历史借阅</a></dd>
                    <dd><a href="/user/Index/changePassword">修改密码</a></dd>
                    <dd><a href="javascript:;" id="loginOut">注销</a></dd>
                </dl>
            </li>
        </ul>
    </div>
</div>

<div class="layui-row">
    <div class="layui-tab">
        <ul class="layui-tab-title">
            <li class="layui-this">修改密码</li>
        </ul>
    </div>
    <div class="layui-col-xs11">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">*用户名</label>
                <div class="layui-input-block">
                    <input type="text" name="username" lay-verify="required" autocomplete="off"
                           placeholder="请输入用户名"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">*旧密码</label>
                <div class="layui-input-block">
                    <input type="password" name="oldPassword" lay-verify="required" placeholder="请输入旧密码"
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">*新密码</label>
                <div class="layui-input-block">
                    <input type="password" name="newPassword" lay-verify="required" placeholder="请输入新密码"
                           autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item" style="text-align: center">
                <a class="layui-btn" lay-submit="" lay-filter="changePassword">提交</a>
            </div>
        </form>
    </div>
</div>

<script>
    layui.use(['form', 'element'], function () {
        var form = layui.form, layer = layui.layer;
        //表单提交
        form.on('submit(changePassword)', function (data) {
            $.post("{:url('user/Index/changePasswordPost')}", {data: data.field}, function (res) {
                if (res.code == 0) {
                    layer.msg(res.msg, {time: 2000, icon: 5});
                } else {
                    layer.msg(res.msg, {time: 1500, icon: 6});
                    $("input").val('');
                }
            }, "json");
        });
    });
    $(function(){
        //注销按钮监听点击事件
        $("#loginOut").on("click",function(){
            $.ajax({
                url:"{:url('user/Login/loginOut')}",
                type:"get",
                success:function (res) {
                    if(res.code==1){
                        layui.use('layer', function(){
                            var layer = layui.layer;
                            layer.msg('注销成功',{time: 1000});
                            setTimeout(function () {
                                window.location.href = '/user/Login/index';
                            },1000);
                        });
                    }
                }
            });
        });
    });
</script>
</body>
</html>